#include<iostream>
#include<cstring>
using namespace std;
const int N = 3e3 + 10;
int g[N][N];
int dis[N];
int n = 2021;
bool st[N];
int gcd(int a, int b)
{
	return b ? gcd(b, a % b) : a;
}
int fun(int a, int b)
{
	return (a * b) / gcd(a, b);
}
void dij(int x)
{
	memset(dis, 0x3f, sizeof(dis));
	dis[x] = 0;
	for (int i = 0; i < n; i++) {
		int t = -1;
		for (int j = 1; j <= n; j++) {
			if (!st[j] && (t == -1 || dis[t] > dis[j])) {
				t = j;
			}
		}
		st[t] = 1;
		for (int j = 1; j <= n; j++) {
			dis[j] = min(dis[j], dis[t] + g[t][j]);
		}
	}
}
int main()
{
	memset(g, 0x3f, sizeof(g));
	for (int i = 1; i <= 2020; i++) {
		for (int j = i; j <= i + 21; j++) {
			g[i][j] = g[j][i] = min(g[i][j], fun(i, j));
		}
	}
	dij(1);
	cout << dis[2021] << endl;
	return 0;
}